var dbNameVal = '',
    tableNameVal = '',
    selectFactorNoVal='',
    FlagVal = true,
    AnalysisResultTableData = [];
var JobIdVal = '',
    ModelNameVal = '';
var canvas, mapImg = [],
    canvasImg = [];
var tableExport;
var excel, allAnalysisFactors = [],
    newDimessionAndIndex = [],
    allDimessionAndIndex = [],
    allStatisticDatas = [],
    allTableDatas = [],
    paramsDataisHas=false,
    paramsData = {},
    JSYD_YS_Data = {},
    JSYD_SP_Data = {};
var modelFilePath = '',modelFileName = ''
var selectAnalysisFactorVal = '',selectDemissionVal = '',selectSerializeNo = ""
var FXMC = '',
    MXMC = '',
    FXWCSJ = '',
    XZQNAME = '',
    FXYZ;
var myChart = null;
var isAlreadyGetAll = false;
var modelApi = getBaseplatformPort();
layui.config({
    base: '/scripts/layui/layui_exts/',
}).extend({
    excel: 'excel',
});
layui.use(['excel'], function () {
    excel = layui.excel;
});

function initAnalysisResultByFactor(attrModelId, analysisName, modelName, analysisTime,attrXZQNAME) {
    JSYD_YS_Data = {
        "YJJBNTMJ": 0,
        "YJJBNTBFB": 0,
        "XZQS": [
            {
                "SHI": "鄂尔多斯市",
                "XIAN": "xx",
                "SHIMJ": 0
            }
        ],
        "ZYJBNTQKKJFB":"",
        "NYDMJ": 0,
        "NYDBFB": 0,
        "JSYDMJ": 0,
        "JSYDBFB": 0,
        "WLYDMJ": 0,
        "WLYDBFB": 0,
        "XMYDXZFX":"",
        "XMYDXZFXKJFB":"",
        "YTJJSQMJ": 0,
        "YTJJSQBFB": 0,
        "XZJSQMJ": 0,
        "XZJSQBFB": 0,
        "YXJSQMJ": 0,
        "YXJSQBFB": 0,
        "JZJSQMJ":0,
        "JZJSQBFB":0,
        "XMFHGHQK":"",
        "XMFHGHQKKJFB":"",
        "XMMC": "",
        "XMDDS": "",
        "FXWCSJ": "",
        "ZGMMJ": "",
        "GDMJ": ""
    },
    JSYD_SP_Data = {
        "XMMC": "",
        "XMDDS": "",
        "FXWCSJ": "",
        "XMYDFHGHQKMS":"",
        "XMYDXZFXMS":"",
        "XMYDZYNYDQKMS":"",
        "XMYDZYJBNTQKMS":"",
        // "XMYDZYGDQKMS":"",
        "DZZHWXXPGMS":"项目不在地质灾害易发区内。",
        // "XMYDYFKCZYQKMS":""
        "XMYDZYGDQKAGDZLDBTJMJMS":"",
        "XMYDZYGDQKAGDPDTJMJMS":"",
        "XMYDYFKCZYQKAKQZLTJSLHMJMS":"项目不压覆矿产资源。",
        "XMYDYFKCZYQKKCZYCLTJMS":"项目不压覆矿产资源。",
        "XMYDFHGHQK":"",
        "XMYDXZFX":"",
        "XMYDZYNYDQK":"",
        "XMYDZYJBNTQK":"",
        // "XMYDZYGDQK":"",
        "DZZHWXXPG":"",
        // "XMYDYFKCZYQK":""
        "XMYDZYGDQKAGDZLDBTJMJ":"",
        "XMYDZYGDQKAGDPDTJMJ":"",
        "XMYDYFKCZYQKAKQZLTJSLHMJ":"",
        "XMYDYFKCZYQKKCZYCLTJ":"",
        "XMYDFHGHQKKJFB":"",
        "XMYDXZFXKJFB":"",
        "XMYDZYNYDQKKJFB":"",
        "XMYDZYJBNTQKKJFB":"",
        "XMYDZYGDQKKJFB":"",
        "DZZHWXXPGKJFB":"",
        "XMYDYFKCZYQKKJFB":"",
        "GDGYTDMJ":0,
        "GDGYTDBFB":0,
        "GDJTTDMJ":0,
        "GDJTTDBFB":0,
        "YDGYTDMJ":0,
        "YDGYTDBFB":0,
        "YDJTTDMJ":0,
        "YDJTTDBFB":0,
        "LDGYTDMJ":0,
        "LDGYTDBFB":0,
        "LDJTTDMJ":0,
        "LDJTTDBFB":0,
        "CDGYTDMJ":0,
        "CDGYTDBFB":0,
        "CDJTTDMJ":0,
        "CDJTTDBFB":0,
        "QTNYDGYTDMJ":0,
        "QTNYDGYTDBFB":0,
        "QTNYDJTTDMJ":0,
        "QTNYDJTTDBFB":0,
        "JBNTMJ":0,
        "YJJBNTS":[{
            "NAME":"",
            "MJ":0,
            "BFB":0
        }],
        "YF":"1",//项目用地压覆矿产，无压覆：0，有压覆：1
        "YFKC":"0"
    };
    myChart = null
    FXMC = analysisName;
    MXMC = modelName;
    FXWCSJ = analysisTime;
    XZQNAME = attrXZQNAME;
    isAlreadyGetAll = false;
    paramsDataisHas=false;

    paramsData = {};
    selectAnalysisFactorVal = '',
        factorsObj = [];
    if($('#AnalysisResultsContent').css("display") === "block"){
        $('#AnalysisResultsContent').hide();
        featuresDataSource.entities.removeAll();
    }
    //获取分析因子下拉列表，默认显示第一个，点击不同的分析因子，饼图和表格显示不同的数据
    $('#select_analysis_type').empty();
    $.ajax({
        type: "post",
        async: false,
        url: modelApi + "resource/getAnalysisFactor",
        data: {
            oneModelId: attrModelId
        },
        datatype: "json",
        success: function (res) {
            res = JSON.parse(res);
            if (res.code == 200) {
                var results = res.data;
                allAnalysisFactors = results;
                for (var i in results) {
                    var oneDataDict = results[i];
                    $('#select_analysis_type').append("<option attrFactorNO='"+ oneDataDict.MENU_FACTOR_NO +"' value='" + oneDataDict.model_name + "'>" + oneDataDict.model_name + "</option>");
                    factorsObj[oneDataDict.model_name] = oneDataDict
                    if (i == 0) {
                        FXYZ = oneDataDict.model_name
                    } else {
                        FXYZ += '；' + oneDataDict.model_name
                    }
                }
                layui.form.render("select");
                selectAnalysisFactorVal = $("#select_analysis_type  option:selected").val();
                selectFactorNoVal = $("#select_analysis_type  option:selected").attr("attrFactorNO");
                var obj = factorsObj[selectAnalysisFactorVal];
                ShowOneContainerVisible('AnalysisResultsContent');
                initAnalysisResultContent(obj);
                layui.form.on('select(select_analysis_type)', function (data) {
                    selectAnalysisFactorVal = data.value;
                    selectFactorNoVal= $("#select_analysis_type  option:selected").attr("attrFactorNO");
                    var obj1 = factorsObj[selectAnalysisFactorVal];
                    initAnalysisResultContent(obj1);
                });
            } else {
                layui.layer.msg(res.msg, {
                    time: 1000,
                    icon: 5,
                    shift: 6
                })
            }
        }
    });
    layui.form.render("select");
}
//初始化分析结果界面
function initAnalysisResultContent(obj) {
    var dbName = obj.dbname,
        tableName = obj.fileName,
        id = obj.tb_dataexplore_id,
        attrJobId = obj.job_id,
        attrModelName = obj.model_name,
        layerguid = m_MapConfigLayers["analyseMapLayerGuid"],
        layerinfo;
    if(obj.layerInfo && obj.layerinfo!={}&& obj.layerinfo!=[]){
        //TODO 根据后端配置图层动态开始当前矢量服务信息
        layerinfo = obj.layerInfo
        layerinfo["GUID"] = layerguid;
        layerinfo["URL"] = layerinfo.proXyUrl;
        if(cesium.layer3DList[layerguid]){
            deleteServerTypeMap(layerguid,layerinfo);
        }
        try{
            var curLayer = new LayerHelper(layerinfo);
            curLayer.addLayer(true);
        }catch(e){

        }
    }
    JobIdVal = attrJobId;
    ModelNameVal = attrModelName;
    if(obj.tb_dataexplore_id==undefined||obj.tb_dataexplore_id == ""){
        if($("#analysize_bottom").hasClass("bottomContentShow")){
            changeClass("analysize_bottom","noSerializeInfo","bottomContentShow");
        }
    }else{
        if(!$("#analysize_bottom").hasClass("bottomContentShow")){
            changeClass("analysize_bottom","noSerializeInfo","bottomContentShow");
        }
        var obj = [];
        dbNameVal = dbName;
        if (tableName.indexOf(",") == -1) {
            tableNameVal = tableName;
        } else {
            var arr = tableName.split(",")
            tableNameVal = arr[0];
        }
        $('#leftChartsAndTable').html("");
        if (!FlagVal) {
            $('#btn_change_table').attr("title", "表格");
            $('#showTableIcon').css('display', 'block');
            $('#showChartsIcon').css('display', 'none');
            FlagVal = true;
        }
        $('#select_demission_type').empty();
        var results;
        if(isAlreadyGetAll){
            allDimessionAndIndex.map(function (item) {
                for (var i in item) {
                    if (i == attrModelName) {
                        results = item[i];
                    }
                }
            })
        }else{
            results = getDimessionAndIndex(dbName, tableNameVal, id)
        }
        for (var i in results) {
            var oneDataDict = results[i];
            $('#select_demission_type').append("<option value='" + oneDataDict.title + "' indexNo='" + i + "' >" + oneDataDict.title + "</option>");
            obj.push({
                title: oneDataDict.title,
                rows: oneDataDict.dimensionSelected,
                cols: oneDataDict.measureSelected,
                chartType:oneDataDict.chartType,
                aggregate:oneDataDict.aggregate
            })
        }
        layui.form.render("select");
        var firObj = obj;
        selectDemissionVal = $("#select_demission_type  option:selected").val();
        selectSerializeNo = $("#select_demission_type  option:selected").attr("indexNo");
        getStatisticResultData(selectDemissionVal, obj );
        getAnalysisResultTableData(attrJobId, selectDemissionVal, obj);
        layui.form.on('select(select_demission_type)', function (data) {
            selectDemissionVal = data.value;
            selectSerializeNo = $("#select_demission_type  option:selected").attr("indexNo");
            getStatisticResultData(selectDemissionVal, obj);
            getAnalysisResultTableData(attrJobId, selectDemissionVal, obj);
        });
        $('#btn_show_all').click(function (e) {
            updataAnalysisResultTableData(AnalysisResultTableData, selectDemissionVal, obj);
        });
        $('#btn_export_resTable').click(function (e) {
                layer.open({
                        title: '导出',
                        content: `<div class = "layui-form" lay-filter = "form_export" style="margin: 5px;font-size:16px">
                <div style="margin:10px">请选择导出类型：</div>
                <div style="margin:10px" class="layui-form-item">
                    <input type="checkbox" name="export_table" value="分析列表" lay-skin="primary" title="导出为分析列表" checked>
                    <input type="checkbox" name="export_word" value="分析报告" lay-skin="primary" title="导出为分析报告">
                    </div>
                </div>`,
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            var data = form.val('form_export');
                            var len = 0
                            for (var i in data) {
                                len++;
                            }
                            if (len < 1) {
                                layer.msg("请选择导出类型！", {
                                    icon: 5
                                });
                            } else {
                                for (var i in data) {
                                    if (data[i] == "分析列表") {
                                        tableExport.data.map(function(item){
                                            if(item.LAY_TABLE_INDEX||item.LAY_TABLE_INDEX==0){
                                                delete item.LAY_TABLE_INDEX
                                            }
                                        })
                                        var tbdata = tableExport;
                                        var obj = {};
                                        tbdata.cols.map(function (item) {
                                            obj[item.field] = item.title
                                        });
                                        tbdata.data.unshift(obj);
                                        excel.downloadExcel(tbdata.data, FXMC+'应用分析列表', 'xlsx');
                                        tbdata.data.splice(0, 1);
                                    } else if (data[i] == "分析报告") {
                                        $(".loadingAnalysisResult").css("display","flex");
                                        
                                        setTimeout(function(){
                                            if(MXMC != "建设用地审批"){
                                                if(!isAlreadyGetAll){
                                                    getAllCharts();
                                                }
                                            }else{
                                                var SP_allDimessionAndIndex = [];
                                                    allAnalysisFactors.map(factors =>{
                                                        var factorName = factors.model_name;
                                                        var tbname = '';
                                                        if (factors.fileName.indexOf(",") == -1) {
                                                            tbname = factors.fileName;
                                                        } else {
                                                            var arr = factors.fileName.split(",")
                                                            tbname = arr[0];
                                                        }
                                                        if(factors.tb_dataexplore_id==undefined||factors.tb_dataexplore_id==""){
                                                            //该分析因子下没有序列化ID
                                                        }else{
                                                            var oneDimessionAndIndex = getDimessionAndIndex(factors.dbname, tbname, factors.tb_dataexplore_id);
                                                            oneDimessionAndIndex.map(function (key,index) {
                                                                key["dbname"] = factors.dbname;
                                                                key["tablename"] = tbname
                                                            })
                                                            var obj = {}
                                                            obj[factorName] = oneDimessionAndIndex
                                                            SP_allDimessionAndIndex.push(obj);
                                                        }
                                                    });
                                                    var SP_allStatisticDatas=[];
                                                    allAnalysisFactors.map(factors => {
                                                        var factorName = factors.model_name;
                                                        SP_allDimessionAndIndex.map(serialize => {
                                                            var key = Object.entries(serialize)[0][0]
                                                            if(key == factorName){
                                                                serialize[factorName].map(function(item,index){
                                                                    params = {
                                                                        dbname: item.dbname,
                                                                        tablename: item.tablename,
                                                                        rows: item.dimensionSelected ? JSON.stringify(item.dimensionSelected) : "",
                                                                        cols: item.measureSelected ? JSON.stringify(item.measureSelected) : "",
                                                                        filterdata: '',
                                                                        aggregate: item.aggregate,
                                                                        // aggregate: "sum",
                                                                        type: "0",
                                                                        userNo: getCookie('portaluserno')
                                                                    }
                                                                    var oneStatisticData = getStatisticDatas(params);
                                                                    oneStatisticData["rows"] = item.dimensionSelected;
                                                                    oneStatisticData["cols"] = item.measureSelected;
                                                                    oneStatisticData["factor"] = factorName;
                                                                    oneStatisticData["chartType"] = item.chartType;
                                                                    oneStatisticData.data.map(item=>{
                                                                        if(item["SHAPE.AREA"]){
                                                                            //换算单位：平方米转换为公顷
                                                                            item["SHAPE.AREA"] = Number(Number(item["SHAPE.AREA"] * 0.0001).toFixed(4));
                                                                            item["AREA"] = Number(Number(item["AREA"] * 0.0001).toFixed(4));
                                                                        }
                                                                        
                                                                    })
                                                                    var obj = {}
                                                                    obj[item.title] = oneStatisticData;
                                                                    SP_allStatisticDatas.push(obj);
                                                                    var descibe = getAnalysisDescribe({
                                                                        name: factorName,
                                                                        index: index,
                                                                        data: oneStatisticData.data
                                                                    });
                                                                    var ms_key = '';
                                                                    if(serialize[factorName].length > 1){
                                                                        ms_key = makePy(factorName + item.title)[0]+"MS";
                                                                    }else{
                                                                        ms_key = makePy(factorName)[0]+"MS";
                                                                    }
                                                                    JSYD_SP_Data[ms_key] = descibe
                                                                    if(factorName == "项目用地占用农用地情况"){
                                                                        var key1 = "DLDLMC";//DLDLMC地类名称
                                                                        var key2 = "QSXZMC";//QSXZMC权属性质名称
                                                                        var value = "SHAPE.AREA"
                                                                        var oTAG1 = {},wd1 = [],data = oneStatisticData.data;
                                                                        for(var i = 0;i < data.length; i++){
                                                                            if(!oTAG1[data[i][key1]]){
                                                                                oTAG1[data[i][key1]] = "1";
                                                                                var obj = {};
                                                                                obj[key1] = data[i][key1];
                                                                                obj[value] = data[i][value];
                                                                                obj["children"] = [{
                                                                                    "key":data[i][key2],
                                                                                    "value":data[i][value]
                                                                                }];
                                                                                wd1.push(obj);
                                                                            }else{
                                                                                wd1.map(item =>{
                                                                                    if(item[key1] == data[i][key1]){
                                                                                        item[value] = Number(item[value])+Number(data[i][value]);
                                                                                        item.children.push({
                                                                                            "key":data[i][key2],
                                                                                            "value":data[i][value]
                                                                                        })
                                                                                    }
                                                                                });
                                                                            }
                                                                        }
                                                                        for(var i = 0 ; i < wd1.length ; i++){
                                                                            wd1[i]["children"].map((item,index) =>{
                                                                            var nyd_mj_key = makePy(wd1[i][key1] + item.key.substring(0,4))[0] + "MJ"
                                                                            var nyd_bfb_key = makePy(wd1[i][key1] + item.key.substring(0,4))[0] + "BFB"
                                                                                JSYD_SP_Data[nyd_mj_key] = Math.round(item.value * 100) / 100;
                                                                                JSYD_SP_Data[nyd_bfb_key] = Math.round((item.value / wd1[i][value]) * 10000) / 100 + "%";
                                                                            });
                                                                        }
                                                                    }else if(factorName == "项目用地占用基本农田情况"){
                                                                        var data = oneStatisticData.data, total = 0;
                                                                        var key = "ZLDWMC", value = "SHAPE.AREA"
                                                                        var JBNT_ARRAY = [];
                                                                        for(var i = 0 ; i < data.length ; i ++){
                                                                            total += data[i][value];
                                                                        }
                                                                        for(var i = 0 ; i < data.length ; i ++){
                                                                            JBNT_ARRAY.push({
                                                                                "NAME":data[i][key],
                                                                                "MJ":Math.round(data[i][value] * 100) / 100,
                                                                                "BFB":Math.round((data[i][value] / total) * 10000) / 100 + "%"
                                                                            })
                                                                        }
                                                                        JSYD_SP_Data["JBNTMJ"] = total;
                                                                        JSYD_SP_Data["YJJBNTS"] = JBNT_ARRAY
                                                                    }else if(factorName == "项目用地压覆矿产资源情况"){
                                                                        if(item.title == "按矿权种类统计数量和面积"){
                                                                            if(oneStatisticData.data.length < 1){
                                                                                JSYD_SP_Data["YF"] = "0";
                                                                            }else{
                                                                                JSYD_SP_Data["YF"] = "1";
                                                                            }
                                                                        }else if(item.title == "矿产资源储量统计"){
                                                                            //目前先写死
                                                                            JSYD_SP_Data["YFKC"] = "0";
                                                                            // if(oneStatisticData.data.length < 1){
                                                                            //     JSYD_SP_Data["YFKC"] = "0";
                                                                            // }else{
                                                                            //     JSYD_SP_Data["YFKC"] = "1";
                                                                            // }
                                                                        }
                                                                    }
                                                                });
                                                            }
                                                        });
                                                    });
                                                    SP_allStatisticDatas.map(function (item, index) {
                                                        canvasImg = [];
                                                        for (var key in item) {
                                                            setTimeout(function () {
                                                                drawStatisticCharts(item[key].data, item[key].rows, item[key].cols,false,item[key].chartType)
                                                                var oneimgurl = downloadImpByChart("statisticChartsContainer", "统计图" + index);
                                                                canvasImg.push({
                                                                    "factor": item[key].factor,
                                                                    "serializeInfo":key,
                                                                    "imgurl": oneimgurl
                                                                })
                                                            }, 5);
                                                        }
                                                    });
                                            }
                                            
                                            setTimeout(function() {
                                            if(!paramsDataisHas){
                                                if(MXMC == "建设用地预审"){
                                                    var total = 0
                                                    newDimessionAndIndex.map(i=>{
                                                        for(var factor in i){
                                                            //factor:分析因子
                                                            for(wd in i[factor]){
                                                                //wd：维度
                                                                i[factor][wd].map(item=>{
                                                                    var wdAlian = item.wdAlian;
                                                                    var zbAlian = item.zbAlian;
                                                                    var XZQS = [];
                                                                    item.zbDatas.map(key=>{
                                                                        var map_img_key;
                                                                        if(factor!="预审项目占用基本农田情况"){
                                                                            // key[wdAlian] :农用地
                                                                            // key[zbAlian] :8138507.338899915
                                                                            var area_key = makePy(key[wdAlian])[0]+"MJ";
                                                                            var bfb_key = makePy(key[wdAlian])[0]+"BFB";
                                                                            var pie_key = makePy(factor)[0].substring(2);
                                                                            map_img_key = makePy(factor)[0].substring(2)+"KJFB"
                                                                            JSYD_YS_Data[area_key] = key[zbAlian];
                                                                            JSYD_YS_Data[bfb_key] = item.zbDatasNum <= 0 ? "0" : (Math.round(key[zbAlian] / item.zbDatasNum * 10000) / 100.00)
                                                                            canvasImg.map(i=>{
                                                                                if(i.factor == factor){
                                                                                    JSYD_YS_Data[pie_key] = i.imgurl.substring(22)
                                                                                }
                                                                            });
                                                                            if(factor == "预审项目用地现状分析"){
                                                                                total += key[zbAlian];
                                                                            }
                                                                        }
                                                                        else{
                                                                            JSYD_YS_Data["YJJBNTMJ"] = item.zbDatasNum;
                                                                            JSYD_YS_Data["YJJBNTBFB"] = "100";
                                                                            XZQS.push({
                                                                                "SHI":"鄂尔多斯市",
                                                                                "XIAN":key[wdAlian],//数据其实是村
                                                                                "SHIMJ":key[zbAlian]
                                                                            })
                                                                            JSYD_YS_Data["XZQS"]=XZQS
                                                                            map_img_key = makePy(factor)[0].substring(4)+"KJFB"
                                        
                                                                        }
                                                                        JSYD_YS_Data[map_img_key] = dataurl;
                                                                    });
                                                                })
                                                            }
                                                        }
                                                    });
                                                    JSYD_YS_Data["XMMC"] = FXMC;
                                                    JSYD_YS_Data["XMDDS"] = XZQNAME;
                                                    JSYD_YS_Data["FXWCSJ"] = FXWCSJ;
                                                    JSYD_YS_Data["ZGMMJ"] = total;
                                                    JSYD_YS_Data["GDMJ"] = JSYD_YS_Data["NYDMJ"];
                                                    paramsData = JSYD_YS_Data;
                                                    modelFilePath = "d:/word";
                                                    modelFileName = "建设用地预审分析报告模板"
                                                }
                                                else if(MXMC == "建设用地审批"){
                                                    allAnalysisFactors.map(item=>{
                                                        factorName = item.model_name;
                                                        canvasImg.map(i=>{
                                                            if(i.factor == factorName){
                                                                var pie_img_key
                                                                if(factorName == "项目用地占用耕地情况" || factorName == "项目用地压覆矿产资源情况"){
                                                                    pie_img_key = makePy(factorName + i.serializeInfo)[0]
                                                                }else{
                                                                    pie_img_key = makePy(factorName)[0]
                                                                }
                                                                JSYD_SP_Data[pie_img_key] = i.imgurl.substring(22)
                                                            }
                                                        });
                                                        var map_img_key = makePy(factorName)[0]+"KJFB";
                                                        JSYD_SP_Data[map_img_key] = dataurl;
                                                    });
                                                    console.log(JSYD_SP_Data);
                                                    JSYD_SP_Data["XMMC"] = FXMC;
                                                    JSYD_SP_Data["XMDDS"] = XZQNAME;
                                                    JSYD_SP_Data["FXWCSJ"] = FXWCSJ;
                                                    paramsData = JSYD_SP_Data;
                                                    modelFilePath = "d:/word";
                                                    modelFileName = "城市批次用地报告模板"
                                                }
                                                else{
                                                var factorsList = [],wdsList = [],zbsList = [],linesList = [],lineZbList = [];
                                                var oneFactorList = {},oneWdList = {},oneZbList = {},oneLineList = {},oneLineZbList = {};
                                                allAnalysisFactors.map(function(item,index){
                                                    var wds1 = '',imgLen = 0
                                                    newDimessionAndIndex.map(function(wdsAndZbs,index2){
                                                        wdsList = []
                                                        if(wdsAndZbs[item.model_name]){
                                                            var onefactor = wdsAndZbs[item.model_name];
                                                            var wdsLen = 0;
                                                            zbs1 = '';
                                                            for(var wd in onefactor){
                                                                if(wdsLen == 0){
                                                                    wds1 = wd;
                                                                }else{
                                                                    wds1 += "；"+wd
                                                                }
                                                                wdsLen ++;
                                                                
                                                                var oneZbDatas = [];
                                                                zbsList = [],linesList = [];
                                                                onefactor[wd].map(function(zbs,index3){
                                                                    if(index3 == 0){
                                                                        zbs1 = zbs.zbName
                                                                    }else{
                                                                        zbs1 += "、" + zbs.zbName
                                                                    }
                                                                    var ImgURL = "";
                                                                    canvasImg.map(function(imgItem){
                                                                        if(item.model_name == imgItem.factor){
                                                                                if(imgItem.rows == wd&&imgItem.cols == zbs.zbName){
                                                                                var PieImgURL = imgItem.imgurl;
                                                                                    ImgURL = PieImgURL.substring(22);
                                                                                    oneZbList = {
                                                                                        "name":zbs.zbName,//指标名称
                                                                                        "img":ImgURL,//指标1的饼图
                                                                                        "imgIndex":index+2 + "." + (Number(imgLen)+2).toString()//饼图图号
                                                                                    }
                                                                                    zbsList.push(oneZbList);
                                                                                    imgLen++
                                                                            }
                                                                        }
                                                                        
                                                                    });
                                                                    
                                                                    zbs.zbDatas.map(function(oneZbData){
                                                                        var obj = [],obj1 = {},obj2={}
                                                                        obj1[zbs.zbName] = oneZbData[zbs.zbAlian]
                                                                        if(oneZbDatas[oneZbData[zbs.wdAlian]]){
                                                                            oneZbDatas[oneZbData[zbs.wdAlian]].push(obj1)
                                                                        }else{
                                                                            obj.push(obj1)
                                                                            obj2[oneZbData[zbs.wdAlian]] = obj
                                                                            oneZbDatas.push(obj2);
                                                                        }
                                                                    });
                                                                    var ValLen = 0;
                                                                    oneZbDatas.map(function(i){
                                                                        for(var key in i){
                                                                            lineZbList = [];
                                                                            i[key].map(function(val){
                                                                                let keys = Object.keys(val);
                                                                                let index = parseInt(Math.random()*keys.length);
                                                                                
                                                                                lineZbList.push({
                                                                                    "value":val[keys[index]]
                                                                                })
                                                                            })
                                                                            oneLineList = {
                                                                                "index":ValLen+1,//表格行号
                                                                                "wd":key,//维度值
                                                                                "zbs":lineZbList//维度值A1下的指标值
                                                                            }
                                                                            linesList.push(oneLineList)
                                                                            ValLen++;
                                                                        }
                                                                    });
                                                                });
                                                                oneWdList = {
                                                                    "zbs1":zbs1,//维度1下所有指标
                                                                    "zbs":zbsList,//维度1下指标列表
                                                                    "index":index+2 +"."+ wdsLen  ,//表序号
                                                                    "name":wd,//维度1名称
                                                                    "lines":linesList//表格列表
                                                                }
                                                                wdsList.push(oneWdList)
                                                            }
                                                            oneFactorList = {
                                                                "mapImage":dataurl,//影像图
                                                                "mapImageIndex":index+2 +".1",//影像图图号
                                                                "name":item.model_name,//分析因子A名称
                                                                "wds1":wds1,//分析因子A下的所有维度
                                                                "wds":wdsList//分析因子A下的维度列表
                                                            }
                                                            factorsList.push(oneFactorList);
                                                        }
                                                    });
                                                });
                                                    paramsData = {
                                                        "FXMC": FXMC,//分析名称
                                                        "MXMC": MXMC,//模型名称
                                                        "FXYZ": FXYZ,//分析因子
                                                        "FXWCSJ": FXWCSJ,//分析完成时间
                                                        "analysisFactorList":factorsList//分析因子列表
                                                    };
                                                    modelFilePath = "d:/word";
                                                    modelFileName = "word"
                                                }
                                                paramsDataisHas=true;
                                            }
                                            var formdata = new FormData();
                                            var data = {
                                                path:modelFilePath,
                                                name:modelFileName,
                                                data:JSON.stringify(paramsData)
                                            };
                                            for(var i in data){
                                                formdata.append(i,data[i]);
                                            }
                                            $.ajax({
                                                type: "post",
                                                // async: false,
                                                url: getWordUploadOriginPort() + "word/wordDownload",
                                                data:formdata,
                                                processData : false, 
                                                contentType:false,
                                                datatype: "blob",
                                                success: function (res) {
                                                    var blobContent = new Blob([res]);
                                                    var eleLink = document.createElement('a')
                                                    eleLink.download = FXMC+'应用分析报告.doc'
                                                    eleLink.style.display = 'none'
                                                    eleLink.href = window.URL.createObjectURL(blobContent)
                                                    // 触发点击
                                                    document.body.appendChild(eleLink)
                                                    eleLink.click()
                                                    // 然后移除
                                                    document.body.removeChild(eleLink)
                                                }
                                            });
                                            getStatisticResultData(selectDemissionVal, firObj);
                                            $(".loadingAnalysisResult").hide();
                                            }, 1000);
                                        },5)
                                    }
                                }
                                layer.close(index)
                            }
                            },
                            btn2: function (index) {
                                layer.close(index)
                            }
                        }); layui.form.render();
                })
        }
    
    }

    function ChangeFun() {
        if (FlagVal) {
            //如果显示的是统计图，则切换成表格，隐藏之前的container
            FlagVal = false;
            $('#statisticChartsContainer').css('display', 'none');
            $('#statisticTableContainer').css('display', 'block');
            layui.table.resize('statisticTable');
            $('#btn_change_table').attr("title", "统计图");
            $('#showTableIcon').css('display', 'none');
            $('#showChartsIcon').css('display', 'block');
        } else {
            FlagVal = true;
            $('#statisticChartsContainer').css('display', 'block');
            $('#statisticTableContainer').css('display', 'none');
            $('#btn_change_table').attr("title", "表格");
            $('#showTableIcon').css('display', 'block');
            $('#showChartsIcon').css('display', 'none');
        }
    }
    //初始化左侧饼图和表格数据
    function getStatisticResultData(value, obj) {
        var rows, cols, nowData = [],chartType = '',aggregate = '',
            nowDataNew = [];
        if (obj.length > 0) {
            for (var i in obj) {
                if (value == obj[i].title) {
                    rows = obj[i].rows;
                    cols = obj[i].cols;
                    chartType = obj[i].chartType,
                    aggregate = obj[i].aggregate;
                }
            }
            if(isAlreadyGetAll){
                allStatisticDatas.map(function (item) {
                    for (var key in item) {
                        if (key == value) {
                            nowDataNew = item[key];
                            nowData = nowDataNew.data;
                        }
                    }
                })
            }else{
                var params = {
                    dbname:dbNameVal,
                    tablename:tableNameVal,
                    rows:rows ? JSON.stringify(rows) : "",
                    cols:cols ? JSON.stringify(cols) : "",
                    filterdata:'',
                    // aggregate:"sum",
                    aggregate:aggregate,
                    type:"0",
                    userNo:getCookie ('portaluserno')
                }
                var results = getStatisticDatas(params);
                nowData =  results.data;
                nowDataNew = results;
                nowData.map(item =>{
                    //换算单位：平方米转换为公顷
                    if(item["SHAPE.AREA"]){
                        item["SHAPE.AREA"] = Number(Number(item["SHAPE.AREA"] * 0.0001).toFixed(4));
                        item["AREA"] = Number(Number(item["AREA"] * 0.0001).toFixed(4))
                    }
                });
            }
            if (nowData.length < 1 || nowDataNew.responseData.dimension == null || nowDataNew.responseData.measure == null) {
                $('#leftChartsAndTable').html('<div class="leftContentNodataText">当前分析区域内无“' + value + '”的相关数据</div>');
                $('#descriptionDIV').html('<div class="leftContentNodataText">当前分析区域内无“' + value + '”的相关数据</div>');
            } else {
                setTimeout(function () {
                    //初始化 统计描述 模块
                    getStatisticDirection(results);
                    drawStatisticCharts(nowData, rows,cols, true,chartType);
                    drawStatistisTables(nowData, rows, cols);
                    //TODO 获取描述信息
                    var descibe = getAnalysisDescribe({
                        name: selectAnalysisFactorVal,
                        index: selectSerializeNo,
                        data: nowData
                    });
                    $('#descriptionDIV').text(descibe);
                    $(".loadingAnalysisResult").hide();
                }, 5);
            }
        }
    }

    //统计图，判断chartype,14:堆叠图、15:混合图、其他现在都显示饼图
    //堆积图：2对1，混合图：1对n
    function drawStatisticCharts(nowData, rows,cols, bool,chartType) {
        var ResultData = [];
        var n1 = rows.length;
        var n2 = cols.length;
        var xname = [],yvalue=[];
        for (var i = 0; i < n1; i++) {
            xname.push([]);
        }
        for (var i = 0; i < n2; i++) {
            yvalue.push([]);
        }
        for (var i = 0; i < nowData.length; i++) {
            for (var j in nowData[i]) {
                for (var k = 0; k < n1; k++) {
                    if (j.toString() == rows[k].FIELDNAME)
                        xname[k].push(nowData[i][j]);
                }
                for (var l = 0; l < n2; l++) {
                    if (j.toString() == cols[l].FIELDNAME)
                        yvalue[l].push(parseFloat(nowData[i][j]));
                }
            }
        }
        $('#leftChartsAndTable').html('<div id="statisticChartsContainer" style="width: 100%;height: 100%;"></div>');
        
        var isAnimation = false;
        if (bool) {
            isAnimation = bool;
        }
        option = {}
        if(chartType==14){
            showPileUp(xname, yvalue);
        }else if(chartType==15){
            showBlend(xname, yvalue,cols);
        }else{
            var demisssionDataName = rows[0].FIELDNAME;
            var colDataName = cols[0].FIELDNAME
            nowData.map(function (item, index, arr) {
                ResultData.push({
                    value: item[colDataName],
                    name: item[demisssionDataName],
                    rows: rows
                    // ,jobId:JobId
                })
            });
            let xData = [];
            let total = 0;
            ResultData.forEach(function (item) {
                xData.push(item.name);
                total = item.value + total;
            })
            option = {
                animation: isAnimation,
                tooltip: {
                    trigger: 'item',
                    formatter: params => {
                        var val = params.value
                        var str = `${params.name} : ${val} (${params.percent}%)`
                        return str;
                    },
                },
                legend: {
                    type: 'scroll',
                    orient: 'vartical',
                    top: 'center',
                    right: '10',
                    itemWidth: 8,
                    itemHeight: 8,
                    itemGap: 20,
                    data: xData,
                    textStyle: {
                        color: '#000',
                        rich: {
                            a: {
                                fontSize: 14,
                                color: '#666',
                                width: 85
                            },
                            pre: {
                                fontSize: 14,
                                color: '#666',
                                width: 45
                            },
                            b: {
                                fontSize: 14,
                                color: '#fff',
                            }
                        }
                    },
                    formatter: (name) => {
                        if (!name) return ''
                        return getEqualNewlineString(name, 6) // 根据你的需求修改参数
                    }
                },
                calculable: true,
                series: [{
                    stack: 'a',
                    type: 'pie',
                    // radius: ['10%', '70%'],
                    label: {
                        normal: {
                            show: true,
                            // formatter: '{b}',
                            // borderRadius:20,
                            textStyle: {
                                fontSize: 12,
                                // color:"#FFF"
                            },
                            formatter: params => {
                                return (
                                    params.percent.toFixed(2) + '%'
                                );
                            },
                            position: 'outside',
                        },
                        emphasis: {
                            show: true,
                        },
                    },
                    // itemStyle:{
                    //     borderRadius:10
                    // },
                    labelLine: {
                        normal: {
                            show: true,
                            length: 15,
                            length2: 20,
                        },
                        emphasis: {
                            show: false,
                        },
                    },
                    data: ResultData,
                }, ],
            };
        }
        var dom = document.getElementById('statisticChartsContainer');
        if (option && typeof option === 'object') {
            if (myChart) {
                myChart.clear();
                myChart.dispose();
                myChart = echarts.init(dom);
            } else {
                myChart = echarts.init(dom);
            }
            window.addEventListener("resize", function () {
                myChart.resize();
            });
            myChart.setOption(option, false);
            myChart.on("click", echartsClickEvent);
        }
    }
    //点击饼图事件
    function echartsClickEvent(param) {
        // var name = param.name;
        // console.log(param.value);
        updataAnalysisResultTableData(param)
    }
    //初始化左侧表格
    function drawStatistisTables(nowData, rows, cols) {
        $('#leftChartsAndTable').append('<div id="statisticTableContainer" style="display:none; overflow-y:auto; margin: 0px 10px;width: calc(100% - 20px);height: 100%"><table class="layui-hide" id="statisticTable" lay-filter="statisticTable"></table></div>');
        var tabCols = [{
            type: 'numbers',
            title: '序号',
            align: 'center',
            width: 100
        }];
        rows.map(item => {
            tabCols.push({
                field: item.FIELDNAME,
                title: item.COLUMN_NAME,
                align: 'center'
            })
        });
        cols.map(item => {
            var colTitle = '';
            if(item.FIELDNAME.toString().toLowerCase().indexOf("area") < 0){
                colTitle = item.COLUMN_NAME + "(个)"
            }else{
                colTitle = item.COLUMN_NAME + "(公顷)"
            }
            tabCols.push({
                field: item.FIELDNAME,
                title: colTitle,
                align: 'center'
            })
        });
        layui.table.render({
            elem: '#statisticTable',
            data: nowData,
            title: '统计表',
            cols: [tabCols],
            response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            },
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.rows.item //解析数据列表
                };
            },
            done: function (res, curr, count) {}
        });
        layui.table.resize('statisticTable');
    }
    //获取右侧表格数据
    function getAnalysisResultTableData(jobId, value, obj) {
        ///upload/modelJsonInfo/{jobId}
        var resArr = [],
            resultData = [];
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "upload/modelJsonInfo",
            data: {
                jobId: jobId
            },
            datatype: "json",
            success: function (res) {
                var AllAttributes = [];
                var keys = {};
                var values = [];
                res = JSON.parse(res);
                if (res.code == 200) {
                    var data = res.data;
                    var fieldsNames = data.fieldAliases;
                    for (var field in fieldsNames) {
                        var lowerField = field.toLowerCase();
                        if (lowerField.indexOf("shape") == -1 && lowerField.indexOf("bsm") == -1 && lowerField.indexOf("objectid") == -1 && lowerField.indexOf("bz") == -1 && lowerField.indexOf("ysdm") == -1 && !confirmStrEnding(lowerField, "bh") && !confirmStrEnding(lowerField, "mj") &&
                            !confirmStrEnding(lowerField, "面积") && !confirmStrEnding(lowerField, "序号") && !confirmStrEnding(lowerField, "坐标") && lowerField.indexOf("许可证") == -1 && lowerField.indexOf("有效期") == -1 && lowerField.indexOf("档案号") == -1 && lowerField.indexOf("qyid") == -1 && lowerField.indexOf("zbg") == -1 &&
                            lowerField.indexOf("qbg") == -1 && lowerField.indexOf("备案号") == -1 && lowerField.indexOf("flowsn") == -1) {
                            // keys[field] = field;
                            keys[field] = fieldsNames[field];

                        }
                    }
                    AllAttributes = data.features;
                    allFeaturesNum = data.features.length;
                    if (allFeaturesNum < 1) {
                        if(!$("#noModelInfo").hasClass("bottomContentShow")){
                            changeClass("noModelInfo","analysize_bottom","bottomContentShow");
                        }
                    } else {
                        if($("#noModelInfo").hasClass("bottomContentShow")){
                            changeClass("noModelInfo","analysize_bottom","bottomContentShow");
                        }
                        var url = getFileUploadOriginPort() + 'upload/jobJsonResult';
                        other_objectToGeometry({
                            type: "url",
                            object: url,
                            modelName: ModelNameVal,
                            jobId: JobIdVal
                        });
                        for (var attr in AllAttributes) {
                            var obj = AllAttributes[attr].attributes;
                            for (var i in obj) {
                                var lowerI = i.toLowerCase();
                                if (lowerI.indexOf("shape") != -1 || lowerI.indexOf("bsm") != -1 || lowerI.indexOf("objectid") != -1 || lowerI.indexOf("bz") != -1 || lowerI.indexOf("ysdm") != -1 || confirmStrEnding(lowerI, "bh") || confirmStrEnding(lowerI, "mj") ||
                                    confirmStrEnding(lowerI, "面积") || confirmStrEnding(lowerI, "序号") || confirmStrEnding(lowerI, "坐标") || lowerI.indexOf("许可证") != -1 || lowerI.indexOf("有效期") != -1 || lowerI.indexOf("档案号") != -1 || lowerI.indexOf("qyid") != -1 || lowerI.indexOf("zbg") != -1 ||
                                    lowerI.indexOf("qbg") != -1 || lowerI.indexOf("备案号") != -1 || lowerI.indexOf("flowsn") != -1) {
                                    delete obj[i];
                                }
                            }
                            values.push({
                                attributes: obj
                            });
                        }
                        var resultParam = [];
                        for (var i in values) {
                            var param = {}
                            var item = values[i].attributes;
                            for (var j in keys) {
                                param[keys[j]] = item[j]
                            }
                            resultParam.push(param);
                        }
                        var cols = [];
                        for (var k in keys) {
                            var object = {
                                field: keys[k],
                                title: keys[k],
                                align: 'center',
                                width: 200
                            }
                            cols.push(object)
                        }
                        var resultsData = {
                            data: resultParam,
                            cols: cols
                        }
                        AnalysisResultTableData = resultsData
                        updataAnalysisResultTableData(resultsData, value, obj)
                    }

                } else {
                    layui.layer.msg(res.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    })
                }
            }
        });
    }

    function updataAnalysisResultTableData(data, value, obj) {
        if (value && obj) {
            initAnalysisResultTable(data)
        } else {
            //点击饼图时触发，对表格原始数据进行筛选
            var rowData = data.data.rows
            var dimensionColsName = rowData[0].COLUMN_NAME
            var dimensionSelectedVal = data.name;
            var resData = [];
            AnalysisResultTableData.data.map(function (item, index, arr) {
                if (item[dimensionColsName] == dimensionSelectedVal) {
                    resData.push(item)
                }
            })
            var obj = {
                data: resData,
                cols: AnalysisResultTableData.cols
            }
            initAnalysisResultTable(obj);
            //地图定位的接口
            other_featureSelectByAttribute({
                id: "",
                key: dimensionColsName,
                value: dimensionSelectedVal
            })
        }
    }

    function initAnalysisResultTable(data) {
        var cols = []
        cols.push(data.cols)
        tableExport = data;
        layui.table.render({
            elem: '#resultDetailTable',
            id: 'resultDetailTable',
            data: data.data
                // , toolbar: true
                // ,defaultToolbar: ['filter', 'exports', 'print'] //工具栏右侧图标
                ,
            title: '统计表',
            cols: cols,
            page: true,
            response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            },
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.total, //解析数据长度
                    "data": res.rows.item //解析数据列表
                };
            },
            done: function (res, curr, count) {}
        });
        // layui.table.on('tool(resultDetailTable)', function(obj) {
        //     if(obj.event == "locationOperate"){
        //         var targetFid = obj.data.FID;
        //         //地图定位的接口
        //         other_featureSelectByAttribute({
        //             id: "",
        //             key: "FID",
        //             value: targetFid
        //         })
        //     }
        // })
        layui.table.on('row(resultDetailTable)', function (obj) {
            var targetFid = obj.data.FID;
            //地图定位的接口
            other_featureSelectByAttribute({
                id: "",
                key: "FID",
                value: targetFid
            })
        });
    }
    //判断字符串是否以特定字符串结尾
    function confirmStrEnding(str, target) {
        var start = str.length - target.length;
        var arr = str.substr(start, target.length);
        if (arr == target) {
            return true;
        }
        return false;
    }

    //获取所有图表，不同的分析因子有不同的统计维度和指标， 根据不同的维度和指标显示不同的图表
    function getAllCharts() {
        allDimessionAndIndex = [];
        allStatisticDatas = [];
        newDimessionAndIndex = []
        allAnalysisFactors.map(function (item) {
            var tbname = '';
            if (item.fileName.indexOf(",") == -1) {
                tbname = item.fileName;
            } else {
                var arr = item.fileName.split(",")
                tbname = arr[0];
            }
            if(item.tb_dataexplore_id==undefined||item.tb_dataexplore_id==""){
                //该分析因子下没有序列化ID
            }else{
                var oneDimessionAndIndex = getDimessionAndIndex(item.dbname, tbname, item.tb_dataexplore_id);
                oneDimessionAndIndex.map(function (key) {
                    key["dbname"] = item.dbname;
                    key["tablename"] = tbname
                })
                var obj = {}
                obj[item.model_name] = oneDimessionAndIndex
                allDimessionAndIndex.push(obj);
            }
        });
        allDimessionAndIndex.map(function (item) {
            var params = {};
            for (var key in item) {
                var obj1 = {},
                    obj2 = [];
                item[key].map(function (param) {
                    params = {
                        dbname: param.dbname,
                        tablename: param.tablename,
                        rows: param.dimensionSelected ? JSON.stringify(param.dimensionSelected) : "",
                        cols: param.measureSelected ? JSON.stringify(param.measureSelected) : "",
                        filterdata: '',
                        aggregate: params.aggregate,
                        // aggregate: "sum",
                        type: "0",
                        userNo: getCookie('portaluserno')
                    }
                    var oneStatisticData = getStatisticDatas(params);
                    oneStatisticData["rows"] = param.dimensionSelected;
                    oneStatisticData["cols"] = param.measureSelected;
                    oneStatisticData["factor"] = key;
                    oneStatisticData["chartType"] = param.chartType;
                    var zbDatasNum = 0;
                    oneStatisticData.data.map(item=>{
                        if(item["SHAPE.AREA"]){
                            //换算单位：平方米转换为公顷
                            item["SHAPE.AREA"] = Number(Number(item["SHAPE.AREA"] * 0.0001).toFixed(4));
                            item["AREA"] = Number(Number(item["AREA"] * 0.0001).toFixed(4));
                        }
                        zbDatasNum += Number(item[param.measureSelected[0].FIELDNAME])
                    })
                    var obj = {}
                    obj[param.title] = oneStatisticData;
                    allStatisticDatas.push(obj);

                    if (!obj1[param.dimensionSelected[0].COLUMN_NAME]) {
                        obj2 = [];
                    } 
                    // obj2.push(param.measureSelected[0].COLUMN_NAME)
                    
                    obj2.push({
                        "zbName":param.measureSelected[0].COLUMN_NAME,
                        "zbAlian":param.measureSelected[0].FIELDNAME,
                        "wdName":param.dimensionSelected[0].COLUMN_NAME,
                        "wdAlian":param.dimensionSelected[0].FIELDNAME,
                        "zbDatas":oneStatisticData.data,
                        "zbDatasNum":zbDatasNum
                    })
                    zbDatasNum = 0;
                    obj1[param.dimensionSelected[0].COLUMN_NAME] = obj2
                })
                var obj3 = {};
                obj3[key] = obj1;
                newDimessionAndIndex.push(obj3)
            }
        });
        allStatisticDatas.map(function (item, index) {
            canvasImg = [];
            for (var key in item) {
                setTimeout(function () {
                    drawStatisticCharts(item[key].data, item[key].rows, item[key].cols,false,item[key].chartType)
                    var oneimgurl = downloadImpByChart("statisticChartsContainer", "统计图" + index);
                    canvasImg.push({
                        "factor": item[key].factor,
                        // "dimessionAndIndex": key,
                        "imgurl": oneimgurl,
                        "rows":item[key].rows[0].COLUMN_NAME,
                        "cols":item[key].cols[0].COLUMN_NAME
                    })
                }, 5);
            }
        });
        // var url = getFileUploadOriginPort() + 'upload/jobJsonResult';
        // allAnalysisFactors.map(function (item) {
        //     var modelname = item.model_name;
        //     var jobid = item.job_id;
        //     other_objectToGeometry({
        //         type: "url",
        //         object: url,
        //         modelName: modelname,
        //         jobId: jobid
        //     });
        //     var canvas = viewer.scene.canvas;
        //     var img = Canvas2Image.convertToImage(canvas, canvas.width, canvas.height, 'png');
        //     console.log(img.src)
        //     mapImg.push({
        //         "factor": modelname,
        //         "imgURL": img.src
        //     })
        // });
        isAlreadyGetAll = true
    }

    //获取统计图表数据
    function getStatisticDatas(params) {
        var results = [];
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "dababaseConnect/getSearchData",
            data: params,
            datatype: "json",
            success: function (res) {
                res = JSON.parse(res);
                if (res.code == 200) {
                    results = res.data;
                } else {
                    layui.layer.msg(res.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    });
                }
            }
        });
        return results;
    }

    //获取维度和指标
    function getDimessionAndIndex(dbName, tableNameVal, id) {
        var results = []
        if(id != undefined){
            $.ajax({
                type: "post",
                async: false,
                url: modelApi + "dababaseConnect/getSaveSerializeInfo",
                data: {
                    dbName: dbName,
                    tableName: tableNameVal,
                    id: id
                },
                datatype: "json",
                success: function (res) {
                    res = JSON.parse(res);
                    if (res.code == 200) {
                        results = res.data.data;
                    } else {
                        layui.layer.msg(res.msg, {
                            time: 1000,
                            icon: 5,
                            shift: 6
                        })
                    }
                }
            }); 
        }else{

        }
        return results;
    }

    //下载图表图片，传递图表容器id
    function downloadImpByChart(chartId, name) {
        myChart && myChart.resize();
        var myChart1 = echarts.getInstanceByDom(document.getElementById(chartId));
        var url = myChart1.getConnectedDataURL({
            pixelRatio: 5, //导出的图片分辨率比率,默认是1
            backgroundColor: '#fff', //图表背景色
            excludeComponents: [ //保存图表时忽略的工具组件,默认忽略工具栏
                'toolbox'
            ],
            type: 'png' //图片类型支持png和jpeg
        });
        //         var $a = document.createElement('a');
        // var type = 'png';
        // $a.download = name + '.' + type;
        // $a.target = '_blank';
        // $a.href = url;
        // // Chrome and Firefox
        // if (typeof MouseEvent === 'function') {
        // var evt = new MouseEvent('click', {
        // view: window,
        // bubbles: true,
        // cancelable: false
        // });
        // $a.dispatchEvent(evt);
        // }
        // // IE
        // else {
        // var html = ''

        // '<body style="margin:0;">'
        // '![](' + url + ')'
        // '</body>';
        // var tab = window.open();
        // tab.document.write(html);
        // }
        return url
    };
    //params 要处理的字符串
    //length 每行显示长度
    //图例超出换行方法
    function getEqualNewlineString (params, length) {
        let text = ''
        let count = Math.ceil(params.length / length) // 向上取整数
        // 一行展示length个
        if (count > 1) {
        for (let z = 1; z <= count; z++) {
            text += params.substr((z - 1) * length, length)
            if (z < count) {
            text += '\n'
            }
        }
        } else {
        text += params.substr(0, length)
        }
        return text
    }

    //统计描述
    function getStatisticDirection(res){
        var results = [];
        $.ajax({
            type: "post",
            async: false,
            url: modelApi + "resource/getAnalysisFactorDecriptionByNo",
            data: {
                menuFactorNo:selectFactorNoVal
            },
            datatype: "json",
            success: function (res) {
                res = JSON.parse(res);
                if (res.code == 200) {
                    results = res.data;
                    if(results.decription!=""){
                        if($('#statisDirectionDIV').hasClass("leftContent")||!$('#rightTableDIV').hasClass("rightContentNew")){
                            $('#statisDirectionDIV').removeClass("leftContent");
                            $('#statisDirectionDIV').addClass("leftContentNew");
                            $('#dividerLine').show();
                            $('#rightTableDIV').addClass("rightContentNew");
                        }
                    }else{
                        if($('#statisDirectionDIV').hasClass("leftContentNew")||$('#rightTableDIV').hasClass("rightContentNew")){
                            $('#statisDirectionDIV').removeClass("leftContentNew");
                            $('#statisDirectionDIV').addClass("leftContent");
                            $('#dividerLine').hide();
                            $('#rightTableDIV').removeClass("rightContentNew");
                        }
                    }
                } else {
                    layui.layer.msg(res.msg, {
                        time: 1000,
                        icon: 5,
                        shift: 6
                    });
                }
            }
        });
    }
    //JS模版字符串中占位符替换成对象中的key值
    function getReplaceStr(str, obj) {
        for (let key in obj) {
          str = str.replace(new RegExp('\\$\\{' + key + '\\}', 'g'), obj[key])
        }
        return str
    }
    //交换dom的class，控制显隐
    function changeClass(oldDomId,newDomId,newClass){
        if($("#"+oldDomId).hasClass(newClass)){
            $("#"+oldDomId).removeClass(newClass);
            $("#"+newDomId).addClass(newClass);
        }else{
            $("#"+newDomId).removeClass(newClass);
            $("#"+oldDomId).addClass(newClass);
        }
    }
    // 14 堆积图
    function showPileUp(xdata, yvalue) {
        var dataObj = {};
        var keyList = [];
            var keyList2 = [];
            for (var k = 0 ; k < xdata[0].length ; k ++){
                var key = xdata[0][k];
                var key1 = xdata[1][k];
                var value = yvalue[0][k];
                if(typeof(dataObj[key]) == "undefined"){
                    dataObj[key] = {};
                }
                if(keyList.indexOf(key1) < 0){
                    keyList.push(key1);
                }
                if(keyList2.indexOf(key) < 0){
                    keyList2.push(key);
                }
                dataObj[key][key1] = value;
            }
            var dataList = [];
            for (var j = 0 ; j < keyList.length ; j ++){
                var list = [];
                for (var attr in dataObj){
                    if(typeof(dataObj[attr][keyList[j]]) == "undefined"){
                        dataObj[attr][keyList[j]] = 0;
                    }
                    list.push(Math.round(dataObj[attr][keyList[j]] * 100) / 100);
                }
                var param = {
                    name: keyList[j],
                    type: 'bar',
                    stack: 'Ad',
                    emphasis: {
                        focus: 'series'
                    },
                    data: list
                }
                dataList.push(param);
            }
            option = {
                // title: Object.assign({
                //     text: chart.title
                // }, titleOption),
                tooltip: {
                    show: true,
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                grid: {
                    left: '15px',
                    right: '20px',
                    bottom: '40px',
                    top: '40px',
                    containLabel: true
                },
                toolbox: {
                    show: true,
                    right: '20px',
                    top: '10px',
                    feature: {
                        dataView: {
                            show: false
                        },
                        saveAsImage: {
                            show: true,
                            name: '图',
                            excludeComponents: ['toolbox'],
                            pixelRatio: 2,
                        }
                    },
                    iconStyle: {
                        normal: {
                            // color: 'white', //设置颜色
                        }
                    }
                },
                xAxis: [
                    {
                        type: 'category',
                        data: keyList2
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: dataList,
                dataZoom: {
                    show: true,
                    height: 20,
                    bottom: 16,
                    start: 0,
                    end: 100,
                    handlecolor: '#ddd',
                    handlestyle: {
                        borderColor: '#cacaca',
                        borderWidth: "1",
                        shadowBlur: 2,
                        background: "#ddd",
                        shadowcolor: "#ddd",
                    },
                    type: 'slider',
                },
                formatter: function (val) {
                    clickValue = val[0];
                    var html = '';
                    val.forEach(function (item, index) {
                        var name = item.name;
                        var color = item.color;
                        var seriesName = item.seriesName;
                        var value = item.value || '';
                        if (index == 0) {
                            html += name;
                        }
                        html += '<br><span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + color + ';"></span>' + seriesName + ': ' + value;
                    });
                    return html;
                }
            }
    }
    // 15 混合图
    function showBlend(xdata, yvalue, cols) {
        //1对n关系
        var legend = [];
        var series = [];
        var measureSelected = cols;
        for (var i = 0 ; i < measureSelected.length ; i ++) {
            legend.push(measureSelected[i].COLUMN_NAME);
            if (i == 0) {
                series.push({
                    name: measureSelected[i].COLUMN_NAME,
                    type: 'bar',
                    data: yvalue[0]
                });
            } else {
                series.push({
                    name: measureSelected[i].COLUMN_NAME,
                    type: 'line',
                    yAxisIndex: 1,
                    data: yvalue[i]
                });
            }
        }
        option = { //加载数据图表
            // title: Object.assign({
            //     text: chart.title
            // }, titleOption),
            tooltip: {
                show: true,
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            grid: {
                left: '15px',
                right: '20px',
                bottom: '40px',
                top: '40px',
                containLabel: true
            },
            legend: {
                data: legend
            },
            xAxis: [
                {
                    type: 'category',
                    data: xdata[0],
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLabel: {
                        formatter: '{value}'
                    }
                },
                {
                    type: 'value',
                    axisLabel: {
                        formatter: '{value}'
                    }
                }
            ],
            series: series
        }
    }